package com.ymk.cmd;

import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.utlis.ParamsBuilder;
import com.ymk.bo.work.WorkToTypeBO;
import com.ymk.core.code.cmd.WorkToTypeCmdCode;
import com.ymk.service.IWorkToTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class WorkToTypeGetCmd extends ACmd {

    @Override
    public CmdSign executeMop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        WorkToTypeBO reqData = super.getData(sign, WorkToTypeBO.class);

        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("workId",reqData.getWorkId())
            .setReturnStruct(sign.getReturnStruct());
        WorkToTypeBO respData = this.workToTypeService.get(paramsBuilder.build());
        respSign.setSource(super.getSource(respData));

        return respSign;
    }

    @Override
    public CmdSign executeSop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        WorkToTypeBO reqData = super.getData(sign, WorkToTypeBO.class);

        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("workId",reqData.getWorkId())
                .setReturnStruct(sign.getReturnStruct());
        WorkToTypeBO respData = this.workToTypeService.get(paramsBuilder.build());
        respSign.setSource(super.getSource(respData));

        return respSign;
    }

    @Override
    public String getCmdCode() {
        return WorkToTypeCmdCode.WORK_TO_TYPE_GET;
    }

    @Override
    public boolean anon(CmdSign sign) {
        return true;
    }
    @Autowired
    private IWorkToTypeService workToTypeService;
}